home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / MenuStuff.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  2KB  |  119 lines

  1. extern struct TextAttr StandardFont;
  2.  
  3. struct MetaMenu
  4. {
  5.     struct MenuItem        Item;
  6.     struct IntuiText    Text;
  7. };
  8.  
  9. STATIC struct MenuItem *LastItem;
  10.  
  11. VOID
  12. ClearMenu(struct Menu *Menu)
  13. {
  14.     struct MenuItem *Item,*NextItem;
  15.  
  16.     if(Item = Menu -> FirstItem)
  17.     {
  18.         NextItem = Item -> NextItem;
  19.  
  20.         FreeMem(Item,sizeof(struct MetaMenu) + 10);
  21.  
  22.         Item = NextItem;
  23.     }
  24.  
  25.     FreeMem(Menu,sizeof(struct Menu));
  26. }
  27.  
  28. struct Menu *
  29. CreateMenu(UBYTE *Title)
  30. {
  31.     struct Menu *Menu;
  32.  
  33.     if(Menu = (struct Menu *)AllocMem(sizeof(struct Menu),MEMF_PUBLIC|MEMF_CLEAR))
  34.     {
  35.         Menu -> LeftEdge    = 2;
  36.         Menu -> Flags        = MENUENABLED;
  37.         Menu -> MenuName    = Title;
  38.         Menu -> Width        = strlen(Title) * 8 + 8;
  39.     }
  40.  
  41.     return(Menu);
  42. }
  43.  
  44. struct MenuItem *
  45. AddItem(struct Menu *Menu,UBYTE *Text,UBYTE Command)
  46. {
  47.     struct MetaMenu    *Meta;
  48.  
  49.     if(Meta = (struct MetaMenu *)AllocMem(sizeof(struct MetaMenu) + 10,MEMF_PUBLIC|MEMF_CLEAR))
  50.     {
  51.         LONG Width = strlen(Text);
  52.  
  53.         if(LastItem)
  54.         {
  55.             LastItem -> NextItem = &Meta -> Item;
  56.  
  57.             Meta -> Item . TopEdge = LastItem -> TopEdge + LastItem -> Height;
  58.         }
  59.  
  60.         LastItem = &Meta -> Item;
  61.  
  62.         if(Command)
  63.             Width += 4;
  64.  
  65.         Meta -> Item . Width    = (Width * 8) + 4;
  66.         Meta -> Item . Height    = 10;
  67.  
  68.         Meta -> Item . Flags    = ITEMENABLED|HIGHCOMP|ITEMTEXT;
  69.  
  70.         if(Command)
  71.         {
  72.             Meta -> Item . Flags    |= COMMSEQ;
  73.             Meta -> Item . Width    += 20;
  74.         }
  75.  
  76.         Meta -> Item . ItemFill    = &Meta -> Text;
  77.         Meta -> Item . Command    = Command;
  78.  
  79.         Meta -> Text . FrontPen        = 0;
  80.         Meta -> Text . BackPen        = 1;
  81.         Meta -> Text . DrawMode        = JAM2;
  82.         Meta -> Text . LeftEdge        = 2;
  83.         Meta -> Text . TopEdge        = 1;
  84.         Meta -> Text . ITextFont    = &StandardFont;
  85.         Meta -> Text . IText        = Text;
  86.  
  87.         if(Menu -> FirstItem)
  88.         {
  89.             struct MenuItem    *Item;
  90.             LONG         MaxWidth = 0;
  91.  
  92.             Item = Menu -> FirstItem;
  93.  
  94.             while(Item)
  95.             {
  96.                 if(Item -> Width > MaxWidth)
  97.                     MaxWidth = Item -> Width;
  98.  
  99.                 Item = Item -> NextItem;
  100.             }
  101.  
  102.             Item = Menu -> FirstItem;
  103.  
  104.             while(Item)
  105.             {
  106.                 Item -> Width = MaxWidth;
  107.  
  108.                 Item = Item -> NextItem;
  109.             }
  110.  
  111. /*            Menu -> Width = MaxWidth + 4;*/
  112.         }
  113.         else
  114.             Menu -> FirstItem = &Meta -> Item;
  115.     }
  116.  
  117.     return(Meta);
  118. }
  119.